package SolveQuestions;

public class JZ23 {
    class Solution {

        public ListNode EntryNodeOfLoop(ListNode pHead) {
            ListNode slow = pHead;
            ListNode quick = pHead;
            if (quick == null) return null;
            while (slow != quick) {
                slow = slow.next;
                quick = quick.next;
                if (quick == null) return null;
                quick = quick.next;
                if (quick == null) return null;
            }
            quick = pHead;
            while (quick != slow) {
                quick = quick.next;
                slow = slow.next;
            }
            return slow;
        }
    }

    public class ListNode {
        int val;
        ListNode next = null;
        ListNode(int val) {
            this.val = val;
        }
    }
}
